package com.fdb.efp.nls.common.util.factory;

import com.fdb.efp.nls.common.constant.PrdInfoEnum;
import com.fdb.efp.nls.common.util.solt.AbstractSoltInfo;
import com.fdb.efp.nls.common.util.solt.NullAdaptedSolt;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2019/12/6
 * 功能描述:
 * 修改日期:2019/12/6
 * 修改描述:
 */
public class SoltFactory {
    private static final Map<String, String> classNameMap = new HashMap<>();
    public static final String CLASS_PREFIX = "com.fdb.efp.nls.common.util.solt.";
    static {
        classNameMap.put(PrdInfoEnum.MASHANG.getPrdId(), "MsAdaptedSolt");
        classNameMap.put(PrdInfoEnum.ZZD.getPrdId(), "ZzdAdaptedSolt");
        classNameMap.put(PrdInfoEnum.MYD.getPrdId(), "MydAdaptedSolt");
        classNameMap.put(PrdInfoEnum.ZXD.getPrdId(), "ZxdAdaptedSolt");
        classNameMap.put(PrdInfoEnum.WSD.getPrdId(), "WsdAdaptedSolt");
        classNameMap.put(PrdInfoEnum.PSD.getPrdId(), "PsdAdaptedSolt");
        classNameMap.put(PrdInfoEnum.SHUIEDAI.getPrdId(), "SedAdaptedSolt");
        classNameMap.put(StringUtils.EMPTY, "NullAdaptedSolt");
    }

    public static AbstractSoltInfo createSolt(String prdId)  {
        if (Objects.isNull(prdId) || Objects.isNull(classNameMap.get(prdId))) return new NullAdaptedSolt();
        try {
            return (AbstractSoltInfo) Class.forName(CLASS_PREFIX+classNameMap.get(prdId)).newInstance();
        } catch (Exception e) {
            return new NullAdaptedSolt();
        }
    }
}
